import%20marimo%0A%0A__generated_with%20%3D%20%220.17.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%2C%20%22ipynb%22%5D)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pytz%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20india_timezone%20%3D%20pytz.timezone(%22Asia%2FKolkata%22)%0A%20%20%20%20now%20%3D%20datetime.datetime.now(india_timezone)%0A%0A%20%20%20%20curr%20%3D%20now.strftime(%22%25Y-%25m-%25d%2C%20%25I%3A%25M%3A%25S%20%25p%20%25Z%22)%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20%23%20Week%20-%209.1%0A%0A%20%20%20%20**Submission%20Date%3A**%20%60This%20assignment%20will%20not%20be%20graded%20and%20is%20only%20for%20practice.%60%0A%0A%20%20%20%20**Last%20Updated%3A**%20%60%7Bcurr%7D%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20sklearn.datasets%20import%20load_iris%0A%20%20%20%20from%20sklearn.cluster%20import%20KMeans%2C%20AgglomerativeClustering%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20return%20AgglomerativeClustering%2C%20KMeans%2C%20load_iris%2C%20plt%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Question%201%20-%204%0A%0A%20%20%20%20-%20Load%20the%20iris%20dataset%20from%20sklearn.%0A%20%20%20%20-%20Remove%20the%20rows%20if%20it%20contain%20NULL%20values.%0A%20%20%20%20-%20Train%20the%20model%20Using%20Kmeans%20Clustering%20by%20setting%20the%20parameter%20as%20following%3A%0A%20%20%20%20%20%20%20%20%60%60%60%0A%20%20%20%20%20%20%20%20%22init%22%3A%20%22random%22%2C%20%22n_init%22%3A%2050%2C%20%22max_iter%22%3A%20500%2C%20%22random_state%22%3A%2010%0A%20%20%20%20%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(load_iris)%3A%0A%20%20%20%20X%2C%20y%20%3D%20load_iris(return_X_y%3DTrue%2C%20as_frame%3DTrue)%0A%20%20%20%20return%20X%2C%20y%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20(X.isna().sum()%20%3E%200).sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(KMeans%2C%20X%2C%20y)%3A%0A%20%20%20%20kmeans%20%3D%20KMeans(%0A%20%20%20%20%20%20%20%20n_clusters%3D5%2C%20init%3D%22random%22%2C%20n_init%3D50%2C%20max_iter%3D500%2C%20random_state%3D10%0A%20%20%20%20)%0A%20%20%20%20kmeans.fit(X%2C%20y)%0A%20%20%20%20return%20(kmeans%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%201%0A%0A%20%20%20%20Which%20feature%20pair%20has%20the%20highest%20correlation%20cofficient%20value%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20X.corr()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%202%0A%0A%20%20%20%20Enter%20the%20value%20of%20the%20'%20%60inertia_%60'%20score%20Keeping%20k%3D5.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(kmeans)%3A%0A%20%20%20%20kmeans.inertia_%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%203%0A%0A%20%20%20%20Plot%20the%20elbow%20chart%20for%20the%20given%20data%20by%20taking%20k%3D1%20to%20k%3D12.%20At%20which%20k%20value%20elbow%20is%20formed%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(KMeans%2C%20X)%3A%0A%20%20%20%20inertias%20%3D%20%5B%5D%0A%20%20%20%20ks%20%3D%20range(1%2C%2013)%0A%20%20%20%20for%20k%20in%20range(1%2C%2013)%3A%0A%20%20%20%20%20%20%20%20km%20%3D%20KMeans(k%2C%20init%3D%22random%22%2C%20n_init%3D50%2C%20max_iter%3D500%2C%20random_state%3D10)%0A%20%20%20%20%20%20%20%20km.fit(X)%0A%20%20%20%20%20%20%20%20inertias.append(km.inertia_)%0A%20%20%20%20return%20inertias%2C%20ks%0A%0A%0A%40app.cell%0Adef%20_(inertias%2C%20ks%2C%20plt)%3A%0A%20%20%20%20plt.plot(ks%2C%20inertias%2C%20marker%3D%22o%22)%0A%20%20%20%20plt.xlabel(%22Number%20of%20clusters%20(k)%22)%0A%20%20%20%20plt.ylabel(%22Inertia%20(SSE)%22)%0A%20%20%20%20plt.title(%22Elbow%20Method%20for%20Optimal%20k%20(Iris%20Dataset)%22)%0A%20%20%20%20plt.grid(True)%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%204%0A%0A%20%20%20%20What%20is%20the%20value%20of%20'%20%60inertia_%60'%20score%20at%20k%3D3.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(inertias)%3A%0A%20%20%20%20inertias%5B2%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Question%205%20-%206%0A%0A%20%20%20%20-%20Load%20the%20iris%20dataset%20from%20sklearn.%0A%20%20%20%20-%20Remove%20the%20rows%20if%20it%20contain%20NULL%20values.%0A%20%20%20%20-%20Train%20the%20model%20using%20Agglomerative%20Clustering%20by%20setting%20the%20parameter%20as%20following%3A%0A%20%20%20%20%20%20%20%20%60%60%60%0A%20%20%20%20%20%20%20%20n_clusters%3D3%2Caffinity%3D'euclidean'%2C%20linkage%3D'ward'%0A%20%20%20%20%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(AgglomerativeClustering%2C%20X%2C%20y)%3A%0A%20%20%20%20aggo%20%3D%20AgglomerativeClustering(%0A%20%20%20%20%20%20%20%20n_clusters%3D3%2C%20metric%3D%22euclidean%22%2C%20linkage%3D%22ward%22%0A%20%20%20%20)%0A%20%20%20%20aggo.fit(X%2C%20y)%0A%20%20%20%20return%20(aggo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%205%0A%0A%20%20%20%20What%20is%20the%20label%20predicted%20for%20last%20row%20of%20samples%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(aggo)%3A%0A%20%20%20%20aggo.labels_%5B-1%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%206%0A%0A%20%20%20%20Enter%20the%20number%20of%20leaves%20in%20the%20hierarchical%20tree.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(aggo)%3A%0A%20%20%20%20aggo.n_leaves_%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
23c8eb1dc17a1dcc54c582d0eff2bd90175edc5d04be68e631bfa1336fedd436